from app import db
from datetime import datetime

class VepParameter(db.Model):
    """VEP核算参数模型"""
    __tablename__ = 'vep_parameters'
    
    id = db.Column(db.Integer, primary_key=True)
    year = db.Column(db.Integer, nullable=False, comment='核算年份')
    vepName = db.Column(db.String(100), nullable=False, comment='VEP项目名称')
    vepCity = db.Column(db.String(50), nullable=False, comment='市级地区名称')
    vepDistrict = db.Column(db.String(50), nullable=False, comment='区级地区名称')
    vepTown = db.Column(db.String(50), nullable=False, comment='镇级地区名称')
    projectArea = db.Column(db.Float, comment='项目占地面积（平方千米）')
    directSalesRevenue = db.Column(db.Float, comment='直接售卖物质产品纯收益（万元/年）')
    processedProductsRevenue = db.Column(db.Float, comment='精深加工产品纯收益（万元/年）')
    townArea = db.Column(db.Float, comment='项目所在乡镇面积（平方千米）')
    regulationServiceValue = db.Column(db.Float, comment='项目所在乡镇调节服务价值（万元）')
    tourismHealthRevenue = db.Column(db.Float, comment='旅游康养纯收益（万元/年）')
    roomPrice = db.Column(db.Float, comment='客房价格（元/间）')
    averageOccupancyRate = db.Column(db.Float, comment='年平均入住率（%）')
    roomCount = db.Column(db.Integer, comment='客房数量（间）')
    realEstateRevenue = db.Column(db.Float, comment='商品房租售交易纯收益（万元/年）')
    dailyVisitorFlow = db.Column(db.Integer, comment='日客流量（人/天）')
    perCapitaDailyConsumption = db.Column(db.Float, comment='人均日消费（元/人）')
    ticketPrice = db.Column(db.Float, comment='门票价格（元/人）')
    creator = db.Column(db.String(50), comment='数据创建者用户名')
    updater = db.Column(db.String(50), comment='数据更新者用户名')
    created_at = db.Column(db.DateTime, default=datetime.utcnow, comment='数据创建时间')
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment='数据更新时间')
    
    def __repr__(self):
        return f'<VepParameter {self.year}-{self.vepName}-{self.vepCity}-{self.vepDistrict}-{self.vepTown}>'
    
    def to_dict(self):
        return {
            'id': self.id,
            'year': self.year,
            'vepName': self.vepName,
            'vepCity': self.vepCity,
            'vepDistrict': self.vepDistrict,
            'vepTown': self.vepTown,
            'projectArea': self.projectArea,
            'directSalesRevenue': self.directSalesRevenue,
            'processedProductsRevenue': self.processedProductsRevenue,
            'townArea': self.townArea,
            'regulationServiceValue': self.regulationServiceValue,
            'tourismHealthRevenue': self.tourismHealthRevenue,
            'roomPrice': self.roomPrice,
            'averageOccupancyRate': self.averageOccupancyRate,
            'roomCount': self.roomCount,
            'realEstateRevenue': self.realEstateRevenue,
            'dailyVisitorFlow': self.dailyVisitorFlow,
            'perCapitaDailyConsumption': self.perCapitaDailyConsumption,
            'ticketPrice': self.ticketPrice,
            'creator': self.creator,
            'updater': self.updater,
            'created_at': self.created_at.isoformat() if self.created_at else None,
            'updated_at': self.updated_at.isoformat() if self.updated_at else None
        } 